package com.dhcc.bpm.modules.auth.granter;

import com.dhcc.bpm.modules.system.entity.UserInfo;
import com.dhcc.bpm.modules.system.service.IUserService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Component;

/**
 * @ClassName PasswordTokenGranter
 * @Description 校验密码
 * @Author xiafayu
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@Component
@AllArgsConstructor
public class PasswordTokenGranter implements ITokenGranter {

    public static final String GRANT_TYPE = "password";
    public static final String PASSWORD = "password";
    public static final String TENANTID = "tenantId";
    public static final String USERNAME = "username";

    private IUserService service;

    /**
     * @param tokenParameter
     * @return com.dhcc.bpm.modules.system.entity.UserInfo
     * @Description 校验密码
     * @Author xiafayu
     * @Date 2020/2/24 17:40
     **/
    @Override
    public UserInfo grant(TokenParameter tokenParameter) {
        String tenantId = tokenParameter.getArgs().getStr(TENANTID);
        String username = tokenParameter.getArgs().getStr(USERNAME);
        String password = tokenParameter.getArgs().getStr(PASSWORD);
        UserInfo userInfo = null;
        if (Func.isNoneBlank(username, password)) {
            userInfo = service.userInfo(tenantId, username, password);
        }
        return userInfo;
    }

}
